package com.zzk.lanouhn.myapplication1.adapters;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.zzk.lanouhn.myapplication1.R;
import com.zzk.lanouhn.myapplication1.modles.KindsDetailsContent;

import java.util.List;

/**
 * 分类二级页面内容部分适配器
 * Created by lanouhn on 16/9/6.
 */
public class KindsDetailsContentsAdapter extends BaseAdapter{
    private Context context;
    private List<KindsDetailsContent.DataBean> detailsContent;

    public KindsDetailsContentsAdapter(Context context, List<KindsDetailsContent.DataBean> detailsContent) {
        this.context = context;
        this.detailsContent = detailsContent;
    }

    @Override
    public int getCount() {
        return detailsContent.size();
    }

    @Override
    public Object getItem(int position) {
        return detailsContent.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = View.inflate(context, R.layout.item_content_kinds_details, null);
            holder.iv_pic = (ImageView) convertView.findViewById(R.id.iv_pic_content_kindsdetails);
            holder.iv_icon = (ImageView) convertView.findViewById(R.id.iv_icon_author_kindsdetails);
            holder.tv_name = (TextView) convertView.findViewById(R.id.tv_author_content_kindsdetails);
            holder.tv_contents = (TextView) convertView.findViewById(R.id.tv_contents_content_kindsdetials);
            holder.tv_likes = (TextView) convertView.findViewById(R.id.tv_likes_content_kindsdetails);
            convertView.setTag(holder);
        } else {
            holder= (ViewHolder) convertView.getTag();
        }
        KindsDetailsContent.DataBean bean=detailsContent.get(position);
        Picasso.with(context).load(bean.getMiddle_pic_url()).into(holder.iv_pic);
        Picasso.with(context).load(bean.getAuthor().getAvatar()).into(holder.iv_icon);
        holder.tv_name.setText(bean.getAuthor().getNickname());
        holder.tv_likes.setText(bean.getDynamic().getLikes());
        holder.tv_contents.setText(bean.getContent());
        return convertView;
    }

    public class ViewHolder{
        private ImageView iv_pic,iv_icon;
        private TextView tv_name,tv_likes,tv_contents;
    }

}
